package com.ruoyi.whzj.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.whzj.domain.WhTasksetting;
import com.ruoyi.whzj.service.IWhTasksettingService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 任务设置Controller
 * 
 * @author ruoyi
 * @date 2020-10-15
 */
@Controller
@RequestMapping("/whzj/tasksetting")
public class WhTasksettingController extends BaseController
{
    private String prefix = "whzj/tasksetting";

    @Autowired
    private IWhTasksettingService whTasksettingService;

    @RequiresPermissions("whzj:tasksetting:view")
    @GetMapping()
    public String tasksetting()
    {
        return prefix + "/tasksetting";
    }

    /**
     * 查询任务设置列表
     */
    @RequiresPermissions("whzj:tasksetting:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WhTasksetting whTasksetting)
    {
        startPage();
        List<WhTasksetting> list = whTasksettingService.selectWhTasksettingList(whTasksetting);
        return getDataTable(list);
    }

    /**
     * 导出任务设置列表
     */
    @RequiresPermissions("whzj:tasksetting:export")
    @Log(title = "任务设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WhTasksetting whTasksetting)
    {
        List<WhTasksetting> list = whTasksettingService.selectWhTasksettingList(whTasksetting);
        ExcelUtil<WhTasksetting> util = new ExcelUtil<WhTasksetting>(WhTasksetting.class);
        return util.exportExcel(list, "tasksetting");
    }

    /**
     * 新增任务设置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存任务设置
     */
    @RequiresPermissions("whzj:tasksetting:add")
    @Log(title = "任务设置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WhTasksetting whTasksetting)
    {
        return toAjax(whTasksettingService.insertWhTasksetting(whTasksetting));
    }

    /**
     * 修改任务设置
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        WhTasksetting whTasksetting = whTasksettingService.selectWhTasksettingById(id);
        mmap.put("whTasksetting", whTasksetting);
        return prefix + "/edit";
    }

    /**
     * 修改保存任务设置
     */
    @RequiresPermissions("whzj:tasksetting:edit")
    @Log(title = "任务设置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WhTasksetting whTasksetting)
    {
        return toAjax(whTasksettingService.updateWhTasksetting(whTasksetting));
    }

    /**
     * 删除任务设置
     */
    @RequiresPermissions("whzj:tasksetting:remove")
    @Log(title = "任务设置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(whTasksettingService.deleteWhTasksettingByIds(ids));
    }
}
